package com.gs.weather.dao;

import com.gs.weather.dao.mapper.DisasterInfoMapper;
import com.gs.weather.entity.DisasterInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Legolas
 * Date: 2017/9/21 0021
 */
@Repository
public class DisasterInfoDao {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    DisasterInfoMapper mapper;

    //添加灾情信息
    public void addDisasterInfo(DisasterInfo disasterInfo) {
        try {
            mapper.addDisasterInfo(disasterInfo);
        } catch (Exception e) {
            logger.info("addDisasterInfo失败->{}", e.getMessage());
        }
    }

    //更新灾情信息
    public void updateDisasterInfo(DisasterInfo disasterInfo) {
        try {
            mapper.updateDisasterInfo(disasterInfo);
        } catch (Exception e) {
            logger.info("updateDisasterInfo失败->{}", e.getMessage());
        }
    }


    //根据id查询灾情信息
    public DisasterInfo queryDisasterInfoById(long id) {
        try {
            DisasterInfo disasterInfo = mapper.queryDisasterInfoById(id);
            return disasterInfo;
        } catch (Exception e) {
            logger.info("queryDisasterInfoById失败->{}", e.getMessage());
            return null;
        }
    }

    public List<DisasterInfo> queryAllDisasterInfosWithCondition(String name, String likeTime){
        try {
            List<DisasterInfo> results = mapper.queryAllDisasterInfoWithXsAreaNameOrTime(name,likeTime);
            return results;
        }catch (Exception e){
            logger.info("queryAllDisasterInfosWithCondition失败->{}", e.getMessage());
            return null;
        }
    }

    //删除灾情信息
    public void deleteDisasterInfo(long id) {
        try {
            mapper.deleteDisasterInfo(id);
        } catch (Exception e) {
            logger.info("deleteDisasterInfo失败->{}", e.getMessage());
        }
    }

}
